package com.zzptc.zzsgz;
public class TestMyTickets implements Runnable{
    private int num=50;//50张票
    public synchronized void run() {
        for(int i=0;i<50;i++) {

                //卖票
                System.out.println("==============start============");
                try {
                    Thread.sleep(3000);
                    if (num > 0) {
                        System.out.println("第" + num-- + "票");
                    } else {
                        System.out.println("没有票了");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("==============end============");
            }

    }
    public static void main(String[] args) {
        TestMyTickets testMyTickets=new TestMyTickets();
        new Thread(testMyTickets).start();
        new Thread(testMyTickets).start();
        new Thread(testMyTickets).start();
    }
}
